<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	TopicDao topicDao = new TopicDaoImpl();//得到主题Dao的实例
	ReplyDao replyDao = new ReplyDaoImpl();//得到回复Dao的实例
	UserDao userDao = new UserDaoImpl();//得到用户Dao的实例
	BoardDao boardDao = new BoardDaoImpl();//得到板块Dao的实例
	
	int boardId = Integer.parseInt(request.getParameter("boardId"));//取得板块ID
	int topicId = Integer.parseInt(request.getParameter("topicId"));//取得主题ID
	int p = Integer.parseInt(request.getParameter("page"));//取得页码
	
	Board board = boardDao.findBoard(boardId);//取得版块信息
	
/* 	int topicId=1;//主题ID暂时固定为1
	int p=1;//页数暂时固定为1 */
	
	Topic topic = topicDao.findTopic(topicId);//取得主题信息
	User topicUser = userDao.findUser(topic.getUserId());//取得主题作者
	List listReply = replyDao.findListReply(p, topicId);//取得该主题的回复列表
	
	int prep = p;//上一页
	int nextp = p;
	if(listReply.size()==10){
		nextp = p+1;
	}
	if(p>1){
		prep = p-1;
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>帖子列表</title>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	
	<style type="text/css">
        	*{
                padding: 0;
                margin: 0;
            }
            #apDiv1{
                width:100%;
                height:50px;
                /*background-color:#e0f0f9;*/
            }
            #apDiv2{
                width:99.5%;
                height:30px;
                background-color:#e0f0f9;
                text-align:left;
            }
            #apDiv3{
                width:99.5%;
                height:25px;
                margin-top: 10px;
                font-size: 20px;
                text-align: center;
            }
            #apDiv4{
                width:99.5%;
                height:25px;
                margin-top: 10px;
                text-align:left;
            }	
            #apDiv5{
                width:99.5%;
                height:25px;
                margin-top: 10px;
                text-align:center;
            }
            #apDiv6{
                width:99.5%;
                height:40px;
                font-size: 20px;
                line-height: 40px;
                margin-top: 15px;
                margin-bottom: 15px;
                background-color: #FFA500;
                text-align:center;
            }
            #apDiv8{
            	width:99.5%;
            	height:25px;
            	text-align:center;
            }
            /*.style1{
                color:#3399cc;
                font-size:36px;
                }*/
            .style1{
                font-family: "黑体";
                font-weight: bold;
                font-size: 40px;
                color: #3399cc;
            }
            .style2{
                color: black;
                font-size: 20px;
            }
            .style3{
            	font-size: 13px;
            	color: #00C758;
            }
			/*.board td{
            	color:3399cc
            }*/
            .user_style{
            	color: #FF8C00;
            	font-size: 20px;
            	/*line-height: 35px;*/
            	font-weight: 700;
            }
        </style>
  </head>
  <body>
		<center>
			<div id="apDiv1">
				<div align="center" class="style1">校园BBS系统</div>
			</div>
			<div class="style2" id="apDiv2">
					&nbsp;您尚未&nbsp;&nbsp;
					<a href="login.jsp" target="_blank">登录</a>
					&nbsp;&nbsp;|&nbsp;&nbsp;
					<a href="reg.jsp" target="_blank">注册</a>	
			</div>
			<div id="apDiv3">
				<a>您所在位置&nbsp;>></a>&nbsp;<a href="index.jsp">&nbsp;论坛首页&nbsp;</a><a>>></a>
				<a href="list.jsp?page=1&boardId=<%=boardId %>">&nbsp;<%=board.getBoardName() %></a>
			</div>
			<div id="apDiv4">
				<table width="99.5%" border="0" cellpadding="0" cellspacing="0">
					<td align="center">
						<a href="post.jsp?topicId=<%=topicId %>&boardId=<%=boardId %>">
							<img src="image/post.gif"/>
						</a>
					</td>
					<td align="center">
						<a href="reply.jsp?boardId=<%=boardId %>">
							<img src="image/reply.gif"/>
						</a>
					</td>
				</table>
			</div>
			<div id="apDiv6">
				本页主题：<%=topic.getTitle() %>
			</div>
			<!-- 主题 -->
			<%
				if(p==1){
			%>
			<div id="apDiv7">
				<table class="board" width="99.5%" border="0" cellpadding="15px" cellspacing="15px">
					<tr>
						<td width="45%">
							<img src="image/head/<%=topicUser.getHead() %>" width="40" height="35"/>&nbsp;
							<span class="user_style"><%=topicUser.getUserName() %></span>
						</td>
						<td>
							<span style="color:#0088FF;font-weight: 600;"><%=topic.getTitle() %></span>
						</td>
					</tr>
					<tr>
						<td colspan="2"><%=topic.getContent() %></td>
					</tr>
					<tr>
						<td colspan="2" align="right">
							<span class="style3">
								注册：<%=topicUser.getRegTime() %>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								发表：<%=topic.getPublishTime() %>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								最后修改：<%=topic.getModifyTime() %>
							</span>
						</td>
					</tr>
				</table><hr>
				<%
				}
				for(int i=0;i<listReply.size();i++){
					Reply reply = (Reply)listReply.get(i);//循环取得回复信息
					User replyUser = (User)userDao.findUser(reply.getUserId());//取得回复的作者
				%>
				<table class="board" width="99.5%" border="0" cellpadding="15px" cellspacing="15px">
					<tr>
						<td width="45%">
							<img src="image/head/<%=topicUser.getHead() %>" width="40" height="35"/>&nbsp;
							<span class="user_style"><%=topicUser.getUserName() %></span>
						</td>
						<td>
							<span style="color:#0088FF;font-weight: 600;"><%=topic.getTitle() %></span>
						</td>
					</tr>
					<tr>
						<td colspan="2"><%=topic.getContent() %></td>
					</tr>
					<tr>
						<td colspan="2" align="right">
							<span class="style3">
								注册：<%=topicUser.getRegTime() %>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								发表：<%=topic.getPublishTime() %>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								最后修改：<%=topic.getModifyTime() %>
								<a href="#">【删除】</a>
								<a href="#">【修改】</a>
							</span>
						</td>
					</tr>
				</table><hr>
				<%} %>
			 </div>
			 <div id="apDiv8">
			 	<a href="detail.jsp?page=<%=prep %>&board=<%=boardId %>&topicId=<%=topicId %>">上一页</a>
			 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 	<a href="detail.jsp?page=<%=nextp %>&board=<%=boardId %>&topicId=<%=topicId %>">下一页</a>
			 </div>
		 </center>
	</body>
</html>
